home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / HTOA.ASM < prev    next >
Assembly Source File  |  1991-11-14  |  2KB  |  92 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7.         extrn    sl_malloc:far
  8. ;
  9. ;
  10. ; Modification 10/22/91 due to comments by David Holm (dgh on BIX).
  11. ;
  12. ;
  13. ; HTOA- Converts value in AL to a string of length two containing two
  14. ;    hexadecimal characters.  Stores result into string at address
  15. ;    ES:DI.
  16. ;
  17. ; HTOA2-Just like HTOA except it does not preserve DI.
  18. ;
  19.         public    sl_htoa
  20. sl_htoa        proc    far
  21.         push    di
  22.         call    far ptr sl_htoa2
  23.         pop    di
  24.         ret
  25. sl_htoa        endp
  26. ;
  27. ;
  28.         public    sl_htoa2
  29. sl_htoa2    proc    far
  30.         push    ax
  31.         call    hextoa
  32.         mov    byte ptr es:[di], 0
  33.         clc                ;Needed by sl_htoam
  34.         pop    ax
  35.         ret
  36. sl_htoa2    endp
  37. ;
  38. ;
  39. ; WTOA- Converts the binary value in AX to a string of four hexadecimal
  40. ;    characters.
  41. ;
  42. ; WTOA2-Like the above, except it does not preserve DI.
  43. ;
  44.         public    sl_wtoa
  45. sl_wtoa        proc    far
  46.         push    di
  47.         call    far ptr sl_wtoa2
  48.         pop    di
  49.         ret
  50. sl_wtoa        endp
  51. ;
  52.         public    sl_wtoa2
  53. sl_wtoa2    proc    far
  54.         push    ax
  55.         xchg    al, ah
  56.         call    hextoa
  57.         xchg    al, ah
  58.         call    hextoa
  59.         mov    byte ptr es:[di], 0
  60.         clc                ;Needed by sl_wtoam
  61.         pop    ax
  62.         ret
  63. sl_wtoa2    endp
  64. ;
  65. ;
  66. ;
  67. hextoa        proc    near
  68.         push    ax
  69.         mov    ah, al
  70.         shr    al, 1
  71.         shr    al, 1
  72.         shr    al, 1
  73.         shr    al, 1
  74.         cmp    al, 0ah        ;Magic sequence to convert 0-F to
  75.         sbb    al, 69h        ; "0"-"F".  By DGH
  76.         das
  77.         mov    es:[di], al
  78.         inc    di
  79.         mov    al, ah
  80.         and    al, 0fh
  81.         cmp    al, 0ah        ;See above comment
  82.         sbb    al, 69h
  83.         das
  84.         mov    es:[di], al
  85.         inc    di
  86.         pop    ax
  87.         ret
  88. hextoa        endp
  89. ;
  90. stdlib        ends
  91.         end
  92.